package com.moorecat.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.*;

import com.moorecat.R;
import com.moorecat.bean.TreeNode;
import com.moorecat.config.Const;

/**
 * @author pengfei.xu
 * @version 创建时间：2011-6-19 上午10:22:29 类说明
 */
public class NearMore extends Activity {

	private ExpandableListView listView;

	private List<Map<String, Object>> groupData = new ArrayList<Map<String, Object>>();

	private List<List<TreeNode>> childData = new ArrayList<List<TreeNode>>();

	private NearMoreAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.near_more);
		listView = (ExpandableListView) findViewById(R.id.listview);
		adapter = new NearMoreAdapter();
		listView.setAdapter(adapter);
		listView.setGroupIndicator(null);
        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener(){

            @Override
            public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
                Intent intent = new Intent();
		        intent.putExtra("type1", "附近");
		        intent.putExtra("typePosition", i);
                intent.setClass(NearMore.this, BusinessList.class);
                intent.putExtra("type2", childData.get(i).get(i1).getName());
			    intent.putExtra("categoryId", childData.get(i).get(i1).getId());
                startActivity(intent);
                return true;
            }
        });
		initGroup();
		initChild();
	}

	private void initGroup() {
		for (int i = 0; i < Const.types.size() - 1; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("name", Const.types.get(i));
			groupData.add(map);
		}
	}

	private void initChild() {
        TreeNode t1 = null;
		List<TreeNode> meishiType = new ArrayList<TreeNode>();
        /**
         * 67    美食
        86            南京/江浙菜
        87            粤菜
        149            川菜
        150            湘菜
        152            新疆/清真
        153            火锅
        154            小吃快餐
        155            日韩料理
        156            东南亚菜
        157            西餐
        158            自助餐
        159            面包甜点
        160            其他

         */
        t1 = new TreeNode(86,"南京/江浙菜", 67);
		meishiType.add(t1);
        t1 = new TreeNode(87,"粤菜", 67);
		meishiType.add(t1);
        t1 = new TreeNode(149,"川菜", 67);
		meishiType.add(t1);
        t1 = new TreeNode(150,"湘菜", 67);
		meishiType.add(t1);
        t1 = new TreeNode(152,"新疆/清真", 67);
		meishiType.add(t1);
        t1 = new TreeNode(153,"火锅", 67);
		meishiType.add(t1);
        t1 = new TreeNode(154,"小吃快餐", 67);
		meishiType.add(t1);
        t1 = new TreeNode(155,"日韩料理", 67);
		meishiType.add(t1);
        t1 = new TreeNode(156,"东南亚菜", 67);
		meishiType.add(t1);
        t1 = new TreeNode(157,"西餐", 67);
		meishiType.add(t1);
        t1 = new TreeNode(158,"自助餐菜", 67);
		meishiType.add(t1);
        t1 = new TreeNode(159,"面包甜点", 67);
		meishiType.add(t1);
        t1 = new TreeNode(160,"其他", 67);
		meishiType.add(t1);
		childData.add(meishiType);
		List<TreeNode> lirenType = new ArrayList<TreeNode>();
        /**
         * 88    丽人
        97            美发
        98            美容/SPA
        99            化妆品
        100            瘦身纤体
        101            新版美甲
        102            舞蹈
        103            其他
        211            个性写真

         */
        t1 = new TreeNode(97,"美发", 88);
		lirenType.add(t1);
        t1 = new TreeNode(98,"美容/SPA", 88);
		lirenType.add(t1);
        t1 = new TreeNode(101,"新版美甲", 88);
		lirenType.add(t1);
        t1 = new TreeNode(99,"化妆品", 88);
		lirenType.add(t1);
        t1 = new TreeNode(100,"瘦身纤体", 88);
		lirenType.add(t1);
        t1 = new TreeNode(102,"舞蹈", 88);
		lirenType.add(t1);
       /* t1 = new TreeNode(211,"个性写真", 88);
		lirenType.add(t1);*/
        t1 = new TreeNode(103,"其他", 88);
		lirenType.add(t1);
		childData.add(lirenType);
		List<TreeNode> huajiaType = new ArrayList<TreeNode>();
        /**
         * 89    花嫁
        104            婚纱摄影
        105            婚宴酒店
        106            婚戒首饰
        107            婚纱礼服
        108            婚庆公司
        109            彩妆造型
        110            其他

         */
        t1 = new TreeNode(107,"婚纱礼服", 89);
		huajiaType.add(t1);
        t1 = new TreeNode(106,"婚戒首饰", 89);
		huajiaType.add(t1);
        t1 = new TreeNode(105,"婚宴酒店", 89);
		huajiaType.add(t1);
        t1 = new TreeNode(104,"婚纱摄影", 89);
		huajiaType.add(t1);
        t1 = new TreeNode(108,"婚庆公司", 89);
		huajiaType.add(t1);
        t1 = new TreeNode(109,"彩妆造型", 89);
		huajiaType.add(t1);
        t1 = new TreeNode(110,"其他", 89);
		huajiaType.add(t1);
		childData.add(huajiaType);
		List<TreeNode> qinziType = new ArrayList<TreeNode>();
        /**
         * 90    亲子
        111            亲子摄影
        112            亲子游乐
        113            早教/幼儿培训
        114            亲子购物
        115            亲子其他

         */
        t1 = new TreeNode(111,"亲子摄影", 90);
		qinziType.add(t1);
        t1 = new TreeNode(112,"亲子游乐", 90);
		qinziType.add(t1);
        t1 = new TreeNode(113,"早教/幼儿培训", 90);
		qinziType.add(t1);
        t1 = new TreeNode(114,"亲子购物", 90);
		qinziType.add(t1);
        t1 = new TreeNode(115,"其他", 90);
		qinziType.add(t1);
		childData.add(qinziType);
		List<TreeNode> jianshenType = new ArrayList<TreeNode>();
        /**
         * 91    健身
        116            瑜伽
        117            健身中心
        118            游泳馆
        119            羽毛球馆
        120            乒乓球馆
        121            网球场
        122            篮球场
        123            足球场
        124            高尔夫场
        125            保龄球馆
        126            台球室
        127            舞蹈
        128            武术场馆
        129            体育场馆
        130            其他

         */
        t1 = new TreeNode(116,"瑜伽", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(117,"健身中心", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(118,"游泳馆", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(120,"乒乓球馆", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(119,"羽毛球馆", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(122,"篮球场", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(121,"网球场", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(123,"足球场", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(124,"高尔夫场", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(125,"保龄球馆", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(126,"台球室", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(127,"舞蹈", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(128,"武术场馆", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(129,"体育场馆", 91);
		jianshenType.add(t1);
        t1 = new TreeNode(130,"其他", 91);
		jianshenType.add(t1);
		childData.add(jianshenType);
		List<TreeNode> peixunType = new ArrayList<TreeNode>();
        /**
         * 92    培训
        131            幼儿
        132            成人
        133            语言
        134            技能
        135            其他

         */
        t1 = new TreeNode(131,"幼儿", 92);
		peixunType.add(t1);
        t1 = new TreeNode(132,"成人", 92);
		peixunType.add(t1);
        t1 = new TreeNode(133,"语言", 92);
		peixunType.add(t1);
        t1 = new TreeNode(134,"技能", 92);
		peixunType.add(t1);
        t1 = new TreeNode(135,"其他", 92);
		peixunType.add(t1);
		childData.add(peixunType);
		List<TreeNode> yuleType = new ArrayList<TreeNode>();
        /**
         * 93    休闲娱乐
        136            咖啡厅
        137            酒吧
        138            茶馆
        139            KTV
        140            电影院
        141            文化艺术
        142            景点/郊游
        143            公园
        144            足疗按摩
        145            游乐游艺
        146            桌面游戏
        147            台球室
        148            其他

         */
        t1 = new TreeNode(136,"咖啡厅", 93);
		yuleType.add(t1);
        t1 = new TreeNode(137,"酒吧", 93);
		yuleType.add(t1);
        t1 = new TreeNode(138,"茶馆", 93);
		yuleType.add(t1);
        t1 = new TreeNode(139,"KTV", 93);
		yuleType.add(t1);
        t1 = new TreeNode(140,"电影院", 93);
		yuleType.add(t1);
        t1 = new TreeNode(141,"文化艺术", 93);
		yuleType.add(t1);
        t1 = new TreeNode(142,"景点/郊游", 93);
		yuleType.add(t1);
        t1 = new TreeNode(143,"公园", 93);
		yuleType.add(t1);
        t1 = new TreeNode(144,"足疗按摩", 93);
		yuleType.add(t1);
        t1 = new TreeNode(145,"游乐游艺", 93);
		yuleType.add(t1);
        t1 = new TreeNode(146,"桌面游戏", 93);
		yuleType.add(t1);
        t1 = new TreeNode(147,"台球室", 93);
		yuleType.add(t1);
        t1 = new TreeNode(148,"其他", 93);
		yuleType.add(t1);
		childData.add(yuleType);
		List<TreeNode> gouwuType = new ArrayList<TreeNode>();
        /**
         * 95    购物
        181            综合商场
        182            食品茶酒
        183            超市/便利店
        184            服饰鞋包
        185            珠宝饰品
        186            化妆品
        187            运动户外
        188            母婴儿童
        189            数码家电
        190            家具家居
        191            特色集市
        192            书店
        193            办公/文化用品
        194            眼镜店
        195            药店
        196            鲜花店
        197            休闲娱乐
        198            其他

         */
        t1 = new TreeNode(181,"综合商场", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(182,"食品茶酒", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(183,"超市/便利店", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(184,"服饰鞋包", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(185,"珠宝饰品", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(186,"化妆品", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(187,"运动户外", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(188,"母婴儿童", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(189,"数码家电", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(190,"家具家居", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(191,"特色集市", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(192,"书店", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(194,"眼镜店", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(193,"办公/文化用品", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(195,"药店", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(196,"鲜花店", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(197,"休闲娱乐", 95);
		gouwuType.add(t1);
        t1 = new TreeNode(198,"其他", 95);
		gouwuType.add(t1);
		childData.add(gouwuType);
		List<TreeNode> jiudianType = new ArrayList<TreeNode>();
        /**
         * 94    酒店
        199            五星级酒店
        200            四星级酒店
        201            三星级酒店
        202            经济型酒店
        203            公寓式酒店
        204            度假村
        205            更多宾馆酒店

         */
        t1 = new TreeNode(199,"五星级酒店", 94);
		jiudianType.add(t1);
        t1 = new TreeNode(200,"四星级酒店", 94);
		jiudianType.add(t1);
        t1 = new TreeNode(201,"三星级酒店", 94);
		jiudianType.add(t1);
        t1 = new TreeNode(204,"度假村", 94);
		jiudianType.add(t1);
        t1 = new TreeNode(203,"公寓式酒店", 94);
		jiudianType.add(t1);
        t1 = new TreeNode(202,"经济型酒店", 94);
		jiudianType.add(t1);
        t1 = new TreeNode(205,"更多宾馆酒店", 94);
		jiudianType.add(t1);
		childData.add(jiudianType);
		List<TreeNode> serviceType = new ArrayList<TreeNode>();
        /**
         * 96    生活服务
        161            室内装潢
        162            居家维修
        163            搬家
        164            旅行社
        165            宠物
        166            齿科
        167            医院
        168            快照/冲印
        169            汽车服务
        170            学校
        171            干洗店
        172            家政
        173            公交车
        174            停车场
        175            加油站
        176            银行
        177            团购网站
        178            小区
        179            商务楼
        180            更多生活服务

         */
        t1 = new TreeNode(161,"室内装潢", 96);
		serviceType.add(t1);
        t1 = new TreeNode(162,"居家维修", 96);
		serviceType.add(t1);
        t1 = new TreeNode(163,"搬家", 96);
		serviceType.add(t1);
        t1 = new TreeNode(164,"旅行社", 96);
		serviceType.add(t1);
        t1 = new TreeNode(165,"宠物", 96);
		serviceType.add(t1);
        t1 = new TreeNode(166,"齿科", 96);
		serviceType.add(t1);
        t1 = new TreeNode(167,"医院", 96);
		serviceType.add(t1);
        t1 = new TreeNode(168,"快照/冲印", 96);
		serviceType.add(t1);
        t1 = new TreeNode(169,"汽车服务", 96);
		serviceType.add(t1);
        t1 = new TreeNode(170,"学校", 96);
		serviceType.add(t1);
        t1 = new TreeNode(171,"干洗店", 96);
		serviceType.add(t1);
        t1 = new TreeNode(172,"家政", 96);
		serviceType.add(t1);
        t1 = new TreeNode(173,"公交车", 96);
		serviceType.add(t1);
        t1 = new TreeNode(174,"停车场", 96);
		serviceType.add(t1);
        t1 = new TreeNode(176,"银行", 96);
		serviceType.add(t1);
        t1 = new TreeNode(175,"加油站", 96);
		serviceType.add(t1);
        t1 = new TreeNode(177,"团购网站", 96);
		serviceType.add(t1);
        t1 = new TreeNode(178,"小区", 96);
		serviceType.add(t1);
        t1 = new TreeNode(179,"商务楼", 96);
		serviceType.add(t1);
        t1 = new TreeNode(180,"更多生活服务", 96);
		serviceType.add(t1);
		childData.add(serviceType);
	}

	public class NearMoreAdapter extends BaseExpandableListAdapter {

		@Override
		public int getGroupCount() {
			return groupData.size();
		}

		@Override
		public int getChildrenCount(int position) {
			return childData.get(position).size();
		}

		@Override
		public Object getGroup(int position) {
			return groupData.get(position);
		}

		@Override
		public Object getChild(int groupPosition, int childPosition) {

			return childData.get(groupPosition).get(childPosition);
		}

		@Override
		public long getGroupId(int paramInt) {
			return paramInt;
		}

		@Override
		public long getChildId(int paramInt1, int paramInt2) {
			return paramInt2;
		}

		@Override
		public boolean hasStableIds() {
			return true;
		}

		@Override
		public View getGroupView(int position, boolean isExpanded,
				View paramView, ViewGroup paramViewGroup) {
			View groupView = paramView;
			if (groupView == null) {
				groupView = (LinearLayout) LayoutInflater.from(NearMore.this)
						.inflate(R.layout.near_more_item, null);
			}
			ImageView btn = (ImageView) groupView.findViewById(R.id.icon);
			TextView name = (TextView) groupView.findViewById(R.id.name);
			name.setText((String) groupData.get(position).get("name"));
			if (isExpanded) {
				btn.setBackgroundResource(R.drawable.b_pull_down);
			} else {
				btn.setBackgroundResource(R.drawable.b_pull_on);
			}
			return groupView;
		}

		@Override
		public View getChildView(int paramInt1, int paramInt2,
				boolean paramBoolean, View paramView, ViewGroup paramViewGroup) {
			View groupView = paramView;
			if (groupView == null) {
				groupView = (LinearLayout) LayoutInflater.from(NearMore.this)
						.inflate(R.layout.near_more_child_item, null);
			}
			TextView name = (TextView) groupView.findViewById(R.id.name);
			name.setText(childData.get(paramInt1).get(paramInt2).getName());
			return groupView;
		}

		@Override
		public boolean isChildSelectable(int paramInt1, int paramInt2) {
			return true;
		}

	}

}
